home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * NOF.js
- *
- * USAGE
- * Part of WPS JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2001 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- /****h* NOF_JavaScript_Library/NOF
- *
- * NAME
- * NOF JavaScript Library / main module.
- *
- * DESCRIPTION
- * Definition of NOF "namespace".
- *
- * NOTES
- * (*) To place another name under this namespace use:
- * NOF.prototype.<your-name> = <whatever>;
- *
- ****/
-
- function IS_getLibHandle()
- {
- return ((typeof(top) != "undefined" && typeof(top._is) != "undefined") ? top._is : // browsers
- ((typeof(top) != "undefined" && typeof(top.opener) != "undefined" && top.opener != null && typeof(top.opener._is) != "undefined") ? top.opener._is : // browsers
- ((typeof(MM) != "undefined" && typeof(MM._is) != "undefined") ? MM._is : // MacroMedia DW
- ((typeof(_is) != "undefined") ? _is : null)))); // ??
- }
-
- var IS = IS_getLibHandle();
- if (!IS_isModuleInitialized("IS.NOF"))
- {
- /****m* NOF/addVariable
- *
- * NAME
- * addVariable( name, initValue )
- *
- * USAGE
- * name -- variable name
- * initValue -- initial value
- *
- * DESCRIPTION
- * Adds a new variable, 'name', to the NOF namespace. If 'initValue' is specified
- * the new variable will be initialized with this value.
- *
- * RETURN VALUE
- * none
- *
- ****/
- function NOF_addVariable(name, initValue) {
- if (arguments.length == 0) { return; }
- if (arguments.length == 1) { initValue = null; }
- eval("NOF." + name + " = initValue");
- }
-
-
- /****m* NOF/delVariable
- *
- * NAME
- * delVariable( name )
- *
- * USAGE
- * name -- variable name
- *
- * DESCRIPTION
- * Removes a variable, 'name', from the NOF namespace
- *
- * RETURN VALUE
- * none
- *
- ****/
- function NOF_delVariable (name) {
- if (arguments.length == 0) { return; }
- if (typeof(eval("NOF." + name)) != "undefined") {
- eval("delete NOF." + name);
- }
- }
-
- /****m* NOF/loadClasses
- *
- * NAME
- * loadClasses( pathNOF, ...)
- *
- * USAGE
- * pathNOF -- comune path to classes (relative to NetObjects System folder
- * the rest of the parameters are the rest of the path to clasess
- *
- * DESCRIPTION
- * load one ore more JS classes (the objects bound to NOF will persist and
- * will be accesible from the momment of loading). Usage sample:
- * NOF.loadClasses(NOF.App.getSystemDirectory() + "FSI/",
- * "lib/nof/dialogs/MySpecialFileDlg",
- * "PhotoGallery/lib/PhotoGallery");
- * MySpecialFileDlg.js and PhotoGallery.js will be loaded
- *
- * RETURN VALUE
- * none
- *
- ****/
- function NOF_loadClasses( pathNOF ) {
- for (var i=1; i < arguments.length; i++) {
- var filePath = pathNOF + arguments[i];
- var fileExtension = filePath.substring(filePath.lastIndexOf(".") + 1);
- if (fileExtension.toLowerCase() != "js") {
- filePath += ".js";
- }
- //alert("filePath = " + filePath);
- if (typeof(NOF.IO.File) == "undefined") {
- /*throw new NOF.UTIL.Exception();*/
- return null;
- }
- var file = new NOF.IO.File(filePath);
- if (!file.exists()) {
- continue;
- }
- var content = file.read();
- if (content != null) {
- try{
- eval(content);
- } catch( exc ) {
- //TODO: ? throw something ?
- var errStr = "Message: " + exc.message + "\n" +
- "File: " + exc.fileName + "\n" +
- "Line: " + exc.lineNumber + "\n" +
- "Name: " + exc.name;
- alert(errStr);
- //return null;
- continue;
- }
- }
- }
- }
-
- /****m* NOF/ensureDependencies
- *
- * NAME
- * ensureDependencies(String[] completeClassNames)
- *
- * USAGE
- * completeClassNames - the list of classes to be checked if initialized.
- * The class name must be given with the complete namespace. The path
- * to the js file (excluding the extension) containg the class can also be used.
- *
- * DESCRIPTION
- * ensure that the classes passed as arguments are loaded
- * (intialized and bound to the correct namespace).
- * If they are not already loaded, the method tries to load them dinamically.
- * Usage sample:
- * NOF.ensureDependencies("NOF.IO.TextElementWriter", "nof/net/Http", "MYNS.DHTML.SpecialEffects");
- *
- *
- * RETURN VALUE
- * none
- *
- ****/
- function NOF_ensureDependencies( /*String[]*/ classNames ) {
- if (typeof(classNames) != "array") {
- if (typeof(classNames) == "string") {
- classNames = [classNames];
- } else {
- return;
- }
- }
-
- var scriptsDirectory = NOF.App.getScriptsDirectory() + NOF.App.PATH_SEPARATOR;
-
- for (var i=0; i < classNames.length; i++) {
- var className = classNames[i];
- var classPath = "";
- if ((className.indexOf("/") == -1) /*&& (className.indexOf("\\") == -1)*/) {
- //it is a NS style name
- classPath = className.replaceSubstr(".", "/"); //NOF.App.PATH_SEPARATOR == /
- } else {
- //it is a file path
- classPath = className;
- className = className.replaceSubstr("/", "."); //NOF.App.PATH_SEPARATOR == /
- // we should do an uppercase here!
- }
- classPath = scriptsDirectory + classPath;
- if (IS_isModuleInitialized("IS." + className)) {
- continue;
- } else {
- try{
- NOF.loadClasses("", classPath);
- } catch( exc ) {
- //TODO: ? throw something ?
- var errStr = "Message: " + exc.message + "\n" +
- "File: " + exc.fileName + "\n" +
- "Line: " + exc.lineNumber + "\n" +
- "Name: " + exc.name;
- alert(errStr);
- //return null;
- continue;
- }
- }
-
- }
- }
-
-
- /****c* NOF
- **
- ** NAME
- ** NOF()
- **
- ** USAGE
- **
- ** DESCRIPTION
- ** Namespace for the Website Pros JS library.
- **
- */
- function NOF () {
- // __proto__ initialization
- this.__proto__ = NOF.prototype;
-
- // properties
- this.type = IS.TYPE_NAMESPACE;
-
- this.addVariable = NOF_addVariable;
- this.delVariable = NOF_delVariable;
- this.loadClasses = NOF_loadClasses;
- this.ensureDependencies = NOF_ensureDependencies;
- }
-
- // add NOF namespace to IS namespace
- IS.__proto__.NOF = new NOF();
- }
-
- var NOF = IS.NOF;
-
- Function.prototype.inherits = function Function_inherits( parent ) {
-
- this.prototype = new parent();
- this.prototype.__super__ = parent;
-
- /*
- //this.prototype = new parent();
- for (baseProp in parent.prototype)
- this.prototype[baseProp] = parent.prototype[baseProp];
-
- this.prototype.__super__ = parent;
- */
- };
-
- Object.prototype.SUPER = function Object_SUPER(){
- this.__proto__.__super__.apply(this, Array.prototype.slice.apply(arguments, [0]));
- }
-
- Object.prototype.release = function Object_release(){
- for (var i in this){
- if (typeof(this[i]) == 'object' && this[i] != null && typeof(this[i].release) == 'function'){
- /*
- if (this[i].toString )
- NOF.SysOut.info("releasing: " + i + "=" + this[i].toString() );
- else
- NOF.SysOut.info("releasing: " + i + "=" + this[i] );
- */
- this[i].release(); //the order being unpredictable could cause problems
- }
-
- if (typeof(this[i]) != 'function' || (this[i] != 'release' && this[i] != 'RELEASE'))
- this[i] = null;
- }
-
- if (this.prototype != null){
- if (typeof(this.prototype.release) == 'function')
- this.prototype.release();
-
- this.prototype.__super__ = null;
- }
-
- this.__proto__ = null;
- this.prototype = null;
- }
-
- Object.prototype.RELEASE = Object_release;
-
- Object.prototype.dump = function Object_dump( showFunctions, obj_name ){
- var prefix = (obj_name == null || obj_name.length == 0 ? "" : obj_name + "." );
- showFunctions = (showFunctions != null ? showFunctions : false);
-
- var result = "";
- for (var i in this)
- if (typeof(this[i]) != 'function' || showFunctions)
- result += prefix + i + " = " + this[i] + "\n";
-
- return result + "\n\n";
- }
-
- Array.prototype.toArray = function () {
- var cloneArray = new Array();
- for (var i = 0; i < this.length; i++) {
- cloneArray.add(this[i]);
- }
- //return this; //?
- }
-
- // Inserts the specified element at the specified position in this array;
- // If the index is not specified then the element is inserted at the end of the array.
- Array.prototype.add = function ( /*Object*/ obj, /*int*/ i) {
-
- if (i != null) {
- if ( (i < 0) || (i > this.length)) {
- return;
- }
- if (i == this.length) {
- this.add(obj);
- return;
- }
- for (var j = this.length - 1; j >= i; j--) {
- this[j+1] = this[j];
- }
- //this[i] = obj;
- } else {
- //this[this.length] = obj;
- i = this.length;
- }
- this[i] = obj;
- }
-
- Array.prototype.item = function (i) {
- return this[i];
- }
-
- Array.prototype.removeItem = function(/*int*/ i) {
-
- if ( i < 0 || i >= this.length){
- return;
- }
-
- for ( var j = i; j < this.length - 1; j++ ) {
- this[j] = this[j+1];
- }
- this[this.length - 1] = null;
- this.length--;
- return;
- }
- Array.prototype.remove = Array.prototype.removeItem;
-
- Array.prototype.containsItem = function(item){
-
- var index = -1;
- var hasEquals = (item.equals)?true:false; //typeof(item.equals)=="function"
-
- if(hasEquals){
- for ( var j = 0; j < this.length; j++ ) {
- if( item.equals(this[j]) ) {
- index = j;
- break;
- }
- }
- }else{
- for ( var j = 0; j < this.length; j++ ) {
- if( item == this[j] ) {
- index = j;
- break;
- }
- }
- }
- return index;
- }
- Array.prototype.contains = Array.prototype.containsItem;
-
-
- String.prototype.trim = function trimString() {
- // Use a regular expression to replace leading and trailing
- // spaces with the empty string
- return this.replace(/(^\s*)|(\s*$)/g, "");
- }
-
- String.prototype.replaceSubstr = function (/*String*/ whatStr, /*String*/ withStr) {
- if ((whatStr == null) || (whatStr.length < 1) ) {
- return this.toString();
- }
- if (withStr == null) {
- withStr = "";
- }
- /*
- var r, re;
- eval("re = /"+ whatStr + "/gm;"); // !this can be dangerous for various instances of whatStr!
- r = this.replace(re, withStr);
- return(r);
- */
- var strArr = this.split(whatStr);
- var str = strArr.join(withStr);
- return str;
-
- }
-
-